﻿using System.Drawing;
using System.Drawing.Imaging;

namespace _18_C_实现将png图片转换成ioc图片
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Bitmap bitmap = new Bitmap(256, 256);//ico图片大小控制

            Graphics g = Graphics.FromImage(bitmap);

            g.Clear(Color.Transparent);

            g.Flush();

            bitmap.Save("test.png", ImageFormat.Png);

            bitmap.Dispose();

            g.Dispose();

            ImageToIco();
        }

        static void ImageToIco()
        {
            string path = "test.ico";

            Bitmap bitmap = new Bitmap("test.png");

            Icon icon = Icon.FromHandle(bitmap.GetHicon());

            using (Stream stream = new FileStream(path, FileMode.Create))
            {
                icon.Save(stream);
            }
            bitmap.Dispose();
            icon.Dispose();
        }
    }
}
